<?php
require_once ROOT_LIBRARY_UTILITY.DS. 'BaseModel.php';

class Model_Solution extends BaseModel{

    public function  __construct() {
        parent::__construct();
        $this->_key = 'id';
        $this->_tableName = 'solutions';
    }

    public function getDataForPagination($where)
    {
        try
        {
            return $this->_db->select()
                    ->from('solutions')
                    ->order('id DESC')
                    ->where($where);
        }
        catch(Zend_Db_Exception $ex)
        {
            throw new Exception($ex);
        }
    }

    public function getByServiceType($serviceTypeId)
    {
        try
        {
            $sql = "SELECT
                                    *
                            FROM
                                    `solutions`
                            WHERE
                                    `service_types_id` = $serviceTypeId";
            $data = $this->_db->fetchAll($sql);

            return $data;
        }
        catch (Zend_Db_Exception $ex)
        {
            return $ex->getMessage();
        }
        catch(Exception $ex)
        {
            return $ex->getMessage();
        }
    }

    public function getAllByServiceTypeId($id)
    {
        try
        {
            $data = array();
            $mdServiceType = new Model_Service_Type();
            $serviceTypes = $mdServiceType->_getAll(" parent_id = $id ");

            if(count($serviceTypes) > 0)
            {
                foreach($serviceTypes as $item)
                {
                    array_push($data, $this->_getAll(" service_types_id = $item->id "));
                    $this->getAllByServiceTypeId($item->id);
                }

            }

            return $data;
        }
        catch(Zend_Db_Exception $ex)
        {
            throw new Exception($ex);
        }
    }
}
?>
